package it.softphone.commons.service.security;

import java.security.GeneralSecurityException;

import javax.security.auth.login.AccountLockedException;
import javax.security.auth.login.AccountNotFoundException;
import javax.security.auth.login.CredentialNotFoundException;


/**
 * 
 * @author softphone
 *
 */
public interface SecurityAccountService  {

	String getId();

	/**
	 * get a principl by type
	 * 
	 * @param <T>
	 * @param type
	 * @return null if there isn't principal for given type
	 */
	<T> T getPrincipal( Class<T> type);
	
	boolean isAuthenticated();
	
	boolean hasRole( String role );
	boolean[] hasRoles( java.util.Collection<String> roles );
	boolean hasAllRoles( java.util.Collection<String> roles );
	
	boolean isPermitted( String permission );
	boolean[] isPermitted( java.util.Collection<String> permissions );
	boolean isPermittedAll( java.util.Collection<String> permissions );

	
	/**
	 * 
	 * @param login
	 * @param password
	 * @param rememberMe
	 * @throws GeneralSecurityException
	 * @throws AccountNotFoundException
	 * @throws CredentialNotFoundException
	 * @throws AccountLockedException
	 */
	void login( String login, String password, boolean rememberMe ) throws GeneralSecurityException, AccountNotFoundException, CredentialNotFoundException, AccountLockedException;
	
	/**
	 * 
	 * @return
	 */
	boolean logout();
 
}
